package org.xg.study.pd.event;

import org.xg.study.pd.ICouponDiscount;

import java.math.BigDecimal;
import java.util.Map;

/**
 * @author CMG
 * @version 1.0
 * @description
 * @cLassName MJCouponDIscount
 * @date 2021/9/18 9:09
 **/
public class MJCouponDiscount implements ICouponDiscount<Map<String, String>> {

    /**
     * 满减计算
     * * 1. 判断满足x元后-n元，否则不减
     * * 2. 最低支付金额1元
     *
     * @param couponInfo 折扣卷信息 ；直减、满减、折扣、N元购
     * @param skuPrice   sku金额
     * @return
     */
    @Override
    public BigDecimal discountAmount(Map<String, String> couponInfo, BigDecimal skuPrice) {
        String x = couponInfo.get("x");
        String o = couponInfo.get("n");
        //小于商品金额条件的，直接返回商品原价
        if (skuPrice.compareTo(new BigDecimal(x)) < 0) {
            return skuPrice;
        }
        //减去优惠金额判断
        BigDecimal discountAmount = skuPrice.subtract(new BigDecimal(o));
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) {
            return BigDecimal.ZERO;
        }
        return discountAmount;
    }
}
